package com.zhipu.hydration.ui.data;

import android.graphics.Color;
import android.os.Bundle;

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.SPUtils;
import com.zhipu.hydration.R;
import com.zhipu.hydration.databinding.ActivityVarietySelectionBinding;
import com.zhipu.hydration.mobile.event.MessageEvent;
import com.zhipu.hydration.ui.BaseActivity;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public class VarietySelectionActivity extends BaseActivity<ActivityVarietySelectionBinding> {
    /**
     * 品种
     */
    private String breed;
    /**
     * 品种位置
     */
    private int breedPosition;

    @Override
    public void initCreate() {
        super.initCreate();
        //注册，重复注册会导致崩溃
        EventBus.getDefault().register(this);
    }

    @Override
    public void initParam() {
        super.initParam();
        breed = getIntent().getExtras().getString("breed");
    }

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_variety_selection;
    }


    @Override
    public void initView() {
        super.initView();
        /**
         * 品种
         */
        switch (breed){
            case "小   麦":
                breedPosition = 4;
                binding.breed4.setTextColor(Color.parseColor("#FF0000"));
                break;
            case "玉   米":
                breedPosition = 5;
                binding.breed5.setTextColor(Color.parseColor("#FF0000"));
                break;
            case "粳   稻":
                breedPosition = 1;
                binding.breed1.setTextColor(Color.parseColor("#FF0000"));
                break;
            case "籼   稻":
                breedPosition = 2;
                binding.breed2.setTextColor(Color.parseColor("#FF0000"));
                break;
            case "大   豆":
                breedPosition = 6;
                binding.breed6.setTextColor(Color.parseColor("#FF0000"));
                break;
            case "稻   谷":
                breedPosition = 3;
                binding.breed3.setTextColor(Color.parseColor("#FF0000"));
                break;
        }


    }

    @Override
    public void initData() {
        super.initData();
        /**
         * 品种
         */
        switch (breedPosition){
            case 4:
                binding.breed1.setTextColor(Color.parseColor("#FFFFFF"));
                binding.breed2.setTextColor(Color.parseColor("#FFFFFF"));
                binding.breed3.setTextColor(Color.parseColor("#FFFFFF"));
                binding.breed4.setTextColor(Color.parseColor("#FF0000"));
                binding.breed5.setTextColor(Color.parseColor("#FFFFFF"));
                binding.breed6.setTextColor(Color.parseColor("#FFFFFF"));
                break;
            case 5:
                binding.breed1.setTextColor(Color.parseColor("#FFFFFF"));
                binding.breed2.setTextColor(Color.parseColor("#FFFFFF"));
                binding.breed3.setTextColor(Color.parseColor("#FFFFFF"));
                binding.breed4.setTextColor(Color.parseColor("#FFFFFF"));
                binding.breed5.setTextColor(Color.parseColor("#FF0000"));
                binding.breed6.setTextColor(Color.parseColor("#FFFFFF"));
                break;
            case 1:
                binding.breed1.setTextColor(Color.parseColor("#FF0000"));
                binding.breed2.setTextColor(Color.parseColor("#FFFFFF"));
                binding.breed3.setTextColor(Color.parseColor("#FFFFFF"));
                binding.breed4.setTextColor(Color.parseColor("#FFFFFF"));
                binding.breed5.setTextColor(Color.parseColor("#FFFFFF"));
                binding.breed6.setTextColor(Color.parseColor("#FFFFFF"));
                break;
            case 2:
                binding.breed1.setTextColor(Color.parseColor("#FFFFFF"));
                binding.breed2.setTextColor(Color.parseColor("#FF0000"));
                binding.breed3.setTextColor(Color.parseColor("#FFFFFF"));
                binding.breed4.setTextColor(Color.parseColor("#FFFFFF"));
                binding.breed5.setTextColor(Color.parseColor("#FFFFFF"));
                binding.breed6.setTextColor(Color.parseColor("#FFFFFF"));
                break;
            case 6:
                binding.breed1.setTextColor(Color.parseColor("#FFFFFF"));
                binding.breed2.setTextColor(Color.parseColor("#FFFFFF"));
                binding.breed3.setTextColor(Color.parseColor("#FFFFFF"));
                binding.breed4.setTextColor(Color.parseColor("#FFFFFF"));
                binding.breed5.setTextColor(Color.parseColor("#FFFFFF"));
                binding.breed6.setTextColor(Color.parseColor("#FF0000"));
                break;
            case 3:
                binding.breed1.setTextColor(Color.parseColor("#FFFFFF"));
                binding.breed2.setTextColor(Color.parseColor("#FFFFFF"));
                binding.breed3.setTextColor(Color.parseColor("#FF0000"));
                binding.breed4.setTextColor(Color.parseColor("#FFFFFF"));
                binding.breed5.setTextColor(Color.parseColor("#FFFFFF"));
                binding.breed6.setTextColor(Color.parseColor("#FFFFFF"));
                break;
        }


    }

    @Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
    public void onMessageEvent(MessageEvent mMessageEvent) {
        switch (mMessageEvent.getType()){
            /**
             * 按键通知
             */
            case Keystroke:
                /**
                 * 按键
                 */
                int mKey = mMessageEvent.getInt();
                switch (mKey){
                    case 1:

                        break;
                    case 2:
                        if(breedPosition >= 1  && breedPosition <= 6){
                            breedPosition --;
                            if(breedPosition <= 0){
                                breedPosition = 1;
                            }
                        }
                        /**
                         * 刷新页面
                         */
                        initData();
                        break;
                    case 3:
                        break;
                    case 4:

                        break;
                    case 5:
                        /**
                         * 打开页面
                         */
                        ActivityUtils.finishActivity(VarietySelectionActivity.class);
                        break;
                    case 6:
                        break;
                    case 7:
                        break;
                    case 8:
                        if(breedPosition >= 1  && breedPosition <= 6){
                            breedPosition ++;
                            if(breedPosition > 6){
                                breedPosition = 6;
                            }
                        }
                        /**
                         * 刷新页面
                         */
                        initData();
                        break;
                    case 9:
                        break;
                }
                /**
                 * 刷新数据
                 */
                initData();
                break;
        }
    }




    @Override
    protected void onDestroy() {
        //解绑
        EventBus.getDefault().unregister(this);
        super.onDestroy();
    }
}
